@extends('admin.main')
@section('head')
    @include('UEditor::head')
    <style>
        .upload-button {
            position: relative;
            display: inline-block;
            padding: 4px 12px;
            overflow: hidden;
            text-decoration: none;
            text-indent: 0;
            line-height: 20px;
            color: #fff;
            background-color: #27ae60;
            text-align: center;
            width: 100px;
        }
        .upload-button input {
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
        }
        .upload-img-box .upload-pre-item {
            float: left;
            padding: 0px;
            margin: 1px 10px 1px 1px;
            width: 150px;
            max-height: 180px;
            overflow: hidden;
            text-align: center;
            cursor: pointer;
            border: 1px solid #ccc;
            transition: all .3s linear;
        }
        .upload-pre-item img{
            border-bottom: 1px solid #ccc;
        }
        .upload-pre-item div{
            background-color: lightgrey;
        }

    </style>
@endsection
@section('body')
    <div class="main-title">
        <h2>{{isset($info['id']) ? '编辑':'新增'}}商品</h2>
    </div>
    <div class="tab-wrap">
        <div class="tab-content">
            <form action="" method="post" class="form-horizontal">
                <!-- 基础 -->
                <div id="tab1" class="tab-pane in tab1">
                    <div class="form-item">
                        <label class="item-label">
                            商品名称<span class="check-tips"></span>
                        </label>
                        <div class="controls">
                            <input type="text" name="goods_name" class="text input-large" readonly value="{{isset($info['goods_name']) ? $info['goods_name'] : ''}}">
                        </div>
                    </div>
                    <div class="controls">
                        <label class="item-label">商品图片<span class="check-tips"></span></label>
                        <input type="hidden" name="goods_img" id="goods_img" value="{{isset($info['goods_img']) ? $info['goods_img'] : ''}}"/>
                        <div class="upload-img-box">

                            @if(isset($info) && $info['pic_num'])
                                @for ($i = 1; $i <= $info['pic_num']; $i++)
                                    <div class="upload-pre-item"  id="goods_img_{{$i}}">
                                        <img src="/uploads/goods/imgs/{{$info['admin_id']}}/{{$info['goods_id']}}_{{$i}}.{{$ext}}?{{time()}}"/>
                                        <input type="hidden" name="pics[]" class="goods_img_{{$i}}"  value="/uploads/goods/imgs/{{$info['admin_id']}}/{{$info['goods_id']}}_{{$i}}.{{$ext}}">
                                    </div>
                                @endfor
                            @endif
                        </div>
                    </div>
                    <div class="form-item">
                        <label class="item-label">
                            市场价格<span class="check-tips">（价格不能小于0）</span>
                        </label>
                        <div class="controls">
                            <input type="text" name="shop_price" class="text input-large" value="{{isset($info['shop_price']) ? $info['shop_price'] : 0}}">
                        </div>
                    </div>
                    <div class="form-item">
                        <label class="item-label">
                            商品价格<span class="check-tips">（价格不能小于0）</span>
                        </label>
                        <div class="controls">
                            <input type="text" name="goods_price" class="text input-large" value="{{isset($info['goods_price']) ? $info['goods_price'] : 0}}">
                        </div>
                    </div>
                </div>
                <dl class="checkmod">
                    <dt class="hd">
                        <label class="checkbox"><input class="auth_rules rules_all" type="checkbox">添加水票套餐</label>
                    </dt>
                    <dd class="bd">
                        @if($billCategory && count($billCategory))
                            <span class="child_row">
                                @foreach($billCategory as $v)
                                    @if($v['status'])
                                    <label class="checkbox">
                                                <input class="auth_rules" type="checkbox"
                                                       name="ids[]"
                                                       value="{{$v['id']}}" @if(isset($info['waterbill_category']) && in_array($v['id'],array_column($info['waterbill_category'],'id'))) checked @endif />{{$v['title']}}
                                            </label>
                                    @endif
                                @endforeach
                                </span>
                        @endif
                    </dd>
                </dl>
                <div class="form-item">
                    <label class="item-label">排序<span class="check-tips">（用于前台显示的顺序，数字越小越靠前）</span></label>
                    <div class="controls">
                        <input type="text" class="text input-small" name="sort" value="{{isset($info['waterbill_category']) ? $info['sort'] : 0}}">
                    </div>
                </div>
                <!-- 高级 -->
                <div class="form-item">
                    <input type="hidden" name="id" value="{{isset($info['id']) ? $info['id'] : ''}}">
                    <input type="hidden" name="shop_id" value="{{isset($info['shop_id']) ? $info['shop_id'] : ''}}">
                    <button type="submit" id="submit" class="btn submit-btn ajax-post" target-form="form-horizontal">确 定
                    </button>
                    <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
                </div>
            </form>
        </div>
    </div>
@endsection

@section('script')
    <script type="text/javascript">

        //全选节点
        $('.rules_all').on('change', function () {
            $(this).closest('dl').find('dd').find('input').prop('checked', this.checked);
        });
        $('.rules_row').on('change', function () {
            $(this).closest('.rule_check').find('.child_row').find('input').prop('checked', this.checked);
        });

    </script>
@endsection
